package repository

import (
	"context"
	"docker-api/internal/model"
	"fmt"
)

type DockerDocRepository interface {
	GetDockerDoc(ctx context.Context) ([]model.DockerDoc, error)
}

func NewDockerDocRepository(
	r *Repository,
) DockerDocRepository {
	return &dockerDocRepository{
		Repository: r,
	}
}

type dockerDocRepository struct {
	*Repository
}

func (r *dockerDocRepository) GetDockerDoc(ctx context.Context) ([]model.DockerDoc, error) {
	var docs []model.DockerDoc
	result := r.db.WithContext(ctx).Find(&docs)
	if result.Error != nil {
		return nil, fmt.Errorf("查询 Docker 文档失败: %w", result.Error)
	}
	return docs, nil
}
